import { Injectable } from '@angular/core'
import { MatDialog } from '@angular/material'
import { MessageDialogComponent, MyMessageData } from '../common/message-dialog/message-dialog.component'
import { Observable } from 'rxjs'

@Injectable()
export class AppMessageDialogService {

  constructor(public dialog: MatDialog) { }

  showMessage(title: string, content: string) {
    const dialogRef = this.dialog.open(MessageDialogComponent, {
      data: {
        'messageOnly': true,
        'title': title,
        'content': content
      },
      closeOnNavigation: true
    })

    dialogRef.afterClosed().subscribe(() => {
    })
  }

  showAuthConfirmForm(url: string, body: any, messageDetail: any): Observable<any> {
    const dialogRef = this.dialog.open(MessageDialogComponent, {
      data: {
        'isConfirmForm': true,
        'postData': {
          'url': url,
          'body': body
        },
        'messageDetail': messageDetail
      },
      closeOnNavigation: true
    })

    return dialogRef.afterClosed()
  }

  showAuthInputForm(messageData: MyMessageData) {
    const dialogRef = this.dialog.open(MessageDialogComponent, {
      data: messageData,
      closeOnNavigation: true
    })

    return dialogRef.afterClosed()
  }
}
